<template>
  <div class="admin">
    <title-vue></title-vue>
    <div class="content">
      <nav-vue></nav-vue>
      <transition name="content">
        <keep-alive>
          <router-view class="content_right" v-if="$store.state.isLogin"></router-view>
        </keep-alive>
      </transition>
    </div>
  </div>
</template>

<script>
import TitleVue from "./title.vue"
import NavVue from "./nav.vue"
import { mapActions, mapMutations } from 'vuex';
export default {
  name: 'Home',

  data() {
    return {
      
    };
  },

  created(){
    this.init()
  },

  methods: {
    init(){
      // 自动登陆
      this.$api.adminToLogin().then(res => {
        if(res == 1){
          this.getUserInfo()
        }else{
          this.showHint({title:'请先登录',isFlag:false})
          this.$router.push('/Admin')
        }
      })
    },
    ...mapActions(['showHint']),
    ...mapMutations(['getUserInfo'])
  },

  components: {
    NavVue,TitleVue
  }
};
</script>

<style scoped>
.content{
  display: flex;
}
.content_right{
  margin-left: 120px;
  flex: 1;
  padding: 20px;
}
</style>